package com.jblank.common.config;

import net.sf.json.JSONObject;

import com.jblank.dto.DTO;

/**
 * 树形配置
 * @author kim
 * @since 2013-08-07
 */
public class TreeConfig {

	private String parent;
	private String node_kind;
	private String node_level;
	private String root_filter;
	private String node_name;
	private String id;

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	public String getNode_kind() {
		return node_kind;
	}

	public void setNode_kind(String node_kind) {
		this.node_kind = node_kind;
	}

	public String getNode_level() {
		return node_level;
	}

	public void setNode_level(String node_level) {
		this.node_level = node_level;
	}

	public String getRoot_filter() {
		return root_filter;
	}

	public void setRoot_filter(String root_filter) {
		this.root_filter = root_filter;
	}

	public String getNode_name() {
		return node_name;
	}

	public void setNode_name(String node_name) {
		this.node_name = node_name;
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	/**
	 * dto解析为config
	 * @param dto
	 * @return treeConfig
	 * 以后可改为反射
	 */
	public static TreeConfig transDtoToConfig(DTO dto){
		TreeConfig treeConfig = null;
		if(dto != null && dto.get(GlobalConfig.TreeConfig) != null){
			treeConfig = new TreeConfig();
			JSONObject treeJson = JSONObject.fromObject(dto.getAsString(GlobalConfig.TreeConfig));
			if(treeJson.has("parent") && treeJson.getString("parent") != null){
				treeConfig.setParent(treeJson.getString("parent"));
			}if(treeJson.has("node_kind") && treeJson.getString("node_kind") != null){
				treeConfig.setNode_kind(treeJson.getString("node_kind"));
			}if(treeJson.has("node_level") && treeJson.getString("node_level") != null){
				treeConfig.setNode_level(treeJson.getString("node_level"));
			}if(treeJson.has("root_filter") && treeJson.getString("root_filter") != null){
				treeConfig.setRoot_filter(treeJson.getString("root_filter"));
			}if(treeJson.has("node_name") && treeJson.getString("node_name") != null){
				treeConfig.setNode_name(treeJson.getString("node_name"));
			}if(treeJson.has("id") && treeJson.getString("id") != null){
				treeConfig.setId(treeJson.getString("id"));
			}
		}
		return treeConfig;
	}
}
